package com.ksu.manager.dao.ibatisImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import com.ksu.manager.dao.IBuyLoseManagerDAO;
import com.ksu.manager.model.BuyLoseManager;
import com.ksu.manager.model.pages.Pagination;
import com.ksu.manager.util.PageQuery;

public class BuyLoseManagerDAOImpl extends SqlSessionDaoSupport implements IBuyLoseManagerDAO {

	@SuppressWarnings("unchecked")
	public Map<String,Object> queryList(BuyLoseManager buyLoseManager,Pagination page) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		try {
            int sum = ((Integer)this.getSqlSession().selectOne("buyLoseManager.selectCount", buyLoseManager)).intValue();
            RowBounds rowBounds = new RowBounds(page.getStartNumber(), page.getPageNumber()); 
            List<BuyLoseManager> buyLoseManagerList = (List<BuyLoseManager>)this.getSqlSession().selectList("buyLoseManager.select",buyLoseManager,rowBounds);
            resultMap = PageQuery.query(page, sum, buyLoseManagerList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}
	
	
	public void create(BuyLoseManager buyLoseManager) {
		try {
			this.getSqlSession().insert("buyLoseManager.insert",buyLoseManager);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public void del(BuyLoseManager buyLoseManager) {
		try {
			this.getSqlSession().delete("buyLoseManager.delete",buyLoseManager);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}


	public void update(BuyLoseManager buyLoseManager) {
		try {
			this.getSqlSession().update("buyLoseManager.update",buyLoseManager);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
